<template>
  <div class="widget-cate">{{ title }}</div>
  <Draggable
    tag="ul"
    item-key="type"
    ghostClass="ghost"
    :group="{ name: 'people', pull: 'clone', put: false }"
    :sort="false"
    :list="list"
  >
    <template #item="{ element }">
      <li
        v-if="fields.includes(element.type)"
        class="form-edit-widget-label"
        :class="{ 'no-put': element.tpye === 'divider' }"
      >
        <a>
          <svg-icon :icon-class="element.type"></svg-icon>
          <span>{{ element.label }}</span>
        </a>
      </li>
    </template>
  </Draggable>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import Draggable from 'vuedraggable'

export default defineComponent({
  name: 'ComponentGroup',
  components: {
    Draggable,
  },
  props: {
    title: {
      type: String,
      required: true
    },
    fields: {
      type: Array as PropType<Array<string>>,
      required: true
    },
    list: {
      required: true
    }
  }
})
</script>

<style lang="scss" scoped>
$primary-color : #409EFF;
$primary-background-color : #ecf5ff;

.components{
  padding: 8px 0;
  width: 100%;
  .widget-cate{
    padding: 8px 12px;
    font-size: 13px;
  }

  ul{
    position: relative;
    overflow: hidden;
    padding: 0 10px 10px;
    margin: 0;
  }

  .form-edit-widget-label{
    box-sizing: border-box;
    font-size: 12px;
    display: block;
    width: 48%;
    line-height: 26px;
    position: relative;
    float: left;
    left: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 1%;
    border: 1px solid #F4F6FC;
    &:hover{
      border: 1px dashed $primary-color;
      &>a{
        color: $primary-color;
      }
    }
    &>a{
      color: #333;
      display: block;
      cursor: move;
      background: #f4f6fc;
      border: 1px solid #f4f6fc;
      :deep(.svg-icon){
        margin-right: 6px;
        margin-left: 8px;
        font-size: 14px;
        display: inline-block;
        vertical-align: middle;
      }
        
      span{
        display: inline-block;
        vertical-align: middle;
      }
    }    
  }
  
}

li.ghost{
  list-style: none;
  font-size: 0;
  overflow: hidden;
}
.ghost{
  background: #f56c6c;
  border: 2px solid #f56c6c;
  position: relative;
  &::after{
    background: #f56c6c;
  }
}

</style>

